﻿#If SKU = "ENTERPRISE" Then
Imports System.Web.UI.WebControls
Imports System.IO

Namespace DotNetNuke.Modules.ActiveForums
    Partial Public Class ActiveForumViewer
        Inherits ForumBase
#Region "Event Handlers"
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                If Not Settings("AFForumModuleID") Is Nothing Then
                    Dim viewType As String = CType(Settings("AFViewType"), String)
                    Dim tmpModuleId As Integer = CInt(Settings("AFForumModuleID"))
                    Dim tmpForumId As Integer = CInt(Settings("AFForumGroupID"))
                    If viewType.ToLowerInvariant = "topics" Then
                        viewType = Views.Topics
                        ctlForumLoader.ForumId = tmpForumId
                    Else
                        viewType = Views.ForumView
                        ctlForumLoader.ForumGroupId = tmpForumId
                    End If
                    ctlForumLoader.DefaultView = viewType
                    ctlForumLoader.ForumModuleId = tmpModuleId
                    ctlForumLoader.ForumTabId = TabId
                    ctlForumLoader.ModuleConfiguration = Me.ModuleConfiguration
                    ctlForumLoader.InheritModuleCSS = False
                    If Not CType(Settings("AFTopicsTemplate"), String) Is Nothing Then
                        ctlForumLoader.DefaultTopicsViewTemplateId = CType(Settings("AFTopicsTemplate"), Integer)
                    End If
                    If Not CType(Settings("AFForumViewTemplate"), String) Is Nothing Then
                        ctlForumLoader.DefaultForumViewTemplateId = CType(Settings("AFForumViewTemplate"), Integer)
                    End If
                    If Not CType(Settings("AFTopicTemplate"), String) Is Nothing Then
                        ctlForumLoader.DefaultTopicViewTemplateId = CType(Settings("AFTopicTemplate"), Integer)
                    End If
                    'Dim objModule As ForumBase = CType(LoadControl("~/desktopmodules/ActiveForums/ActiveForums.ascx"), ForumBase)
                    'If Not objModule Is Nothing Then
                    '    objModule.ModuleConfiguration = Me.ModuleConfiguration
                    '    objModule.ID = Path.GetFileNameWithoutExtension("~/desktopmodules/ActiveForums/ActiveForums.ascx")
                    '    objModule.AFModID = CType(Settings("AFForumModuleID"), Integer)
                    '    objModule.LoadGroupForumID = CType(Settings("AFForumGroupID"), Integer)
                    '    objModule.LoadView = CType(Settings("AFViewType"), String)
                    '    plhMod.Controls.Add(objModule)
                    'End If
                    Dim oLink As System.Web.UI.HtmlControls.HtmlGenericControl = New System.Web.UI.HtmlControls.HtmlGenericControl("link")
                    oLink.Attributes("rel") = "stylesheet"
                    oLink.Attributes("type") = "text/css"
                    oLink.Attributes("href") = Page.ResolveUrl("~/DesktopModules/ActiveForums/module.css")
                    Dim oCSS As System.Web.UI.Control = Me.Page.FindControl("CSS")
                    If Not oCSS Is Nothing Then
                        Dim iControlIndex As Integer = 0
                        iControlIndex = oCSS.Controls.Count
                        oCSS.Controls.AddAt(0, oLink)
                    End If
                Else
                    Dim lblMessage As New Label
                    lblMessage.Text = "Please access the Module Settings page to configure this module."
                    lblMessage.CssClass = "NormalRed"
                    Me.Controls.Add(lblMessage)
                End If
            Catch exc As Exception
                DotNetNuke.Services.Exceptions.ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
#End Region

    End Class
End Namespace
#End If
